home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / admin / saravg < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  2.3 KB  |  87 lines

  1. #!/bin/ksh
  2. # @(#) saravg.ksh 1.2 97/02/05
  3. # 94/02/05 John H. DuBois III (john@armory.com)
  4. # 94/07/06 Added all options.
  5. # 97/02/05 Added o option.  Print formfeeds between output sets.
  6.  
  7. name=${0##*/}
  8. Usage="Usage: $name [-ho] [-aBbcdgHmnpqRruvwy] [-[se] time] [filename ...]"
  9. sarout=false
  10.  
  11. # Save args because some ksh versions lose positional params when set -A is
  12. # used.
  13. set -A files -- "$@"
  14.  
  15. while getopts :hoaBbcdgHmnpqRruvwys:e: opt; do
  16.     case $opt in
  17.     h)
  18.     echo \
  19. "$name: print system activity averages.
  20. $Usage
  21. $name runs 'sar' with any arguments, and prints only the headers and average
  22. values.  If no filenames are given, the current sadc logfile is processed.
  23. Otherwise, sar is run on each named sadc logfile.  If more than one logfile is
  24. given, a formfeed is printed between each output set.  If no report selection
  25. options are given, the default of -A (all reports) is used.  Use -H instead of
  26. -h to get buffer statistics.
  27. Non-sar options:
  28. -h: Print this help.
  29. -o: Take the files to be sar output files rather than sadc logfiles (data
  30.     recorded by sadc, the system activity data collector).  If this option is
  31.     used, no other options may be given; the output will be averages from
  32.     whatever reports sar was asked to generate.  If no filenames are given, the
  33.     standard input is read."
  34.     exit 0
  35.     ;;
  36.     [se])
  37.     set -A args -- "${args[@]}" -$opt "$OPTARG"
  38.     ;;
  39.     [aBbcdgmnpqRruvwy])
  40.     set -A args -- "${args[@]}" -$opt
  41.     ;;
  42.     o)
  43.     sarout=true
  44.     ;;
  45.     H)
  46.     set -A args -- "${args[@]}" -h
  47.     ;;
  48.     +?)
  49.     print -u2 "$name: options should not be preceded by a '+'."
  50.     exit 1
  51.     ;;
  52.     :)
  53.         print -r -u2 -- \
  54.         "$name: Option '$OPTARG' requires a value.  Use -h for help."
  55.         exit 1
  56.         ;;
  57.     ?) 
  58.     print -u2 "$name: $OPTARG: bad option.  Use -h for help."
  59.     exit 1
  60.     ;;
  61.     esac
  62. done
  63.  
  64. if [ ${#args[*]} -eq 0 ]; then
  65.     set -A args -- -A
  66. elif $sarout; then
  67.     print -ru2 -- "$name: -o may not be given with any other options.  Exiting."
  68.     exit 1
  69. fi
  70.  
  71. set -- "${files[@]}"    # Restore args
  72. # remove args that were options
  73. let OPTIND=OPTIND-1
  74. shift $OPTIND
  75.  
  76. if [ $# -eq 0 ]; then
  77.     $sarout && cat || sar "${args[@]}"
  78. else
  79.     while [ $# -gt 0 ]; do
  80.     print -r -- "Input file: $1
  81. "
  82.     $sarout && cat -- "$1" || sar "${args[@]}" -f "$1"
  83.     shift
  84.     [ $# -gt 0 ] && echo -n "\014"
  85.     done
  86. fi | sed -n '/Average/,/^[0-9]/p;1,/^[0-9]/p'
  87.